<template>
  <teleport to="#modal">
    <div class="modal" v-if="isOpen">
      <h2><slot name="modal">this is a modal</slot></h2>
      <button @click="buttonClick">close</button>
    </div>
  </teleport>
</template>

<script lang='ts'>
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'modal',
  props: {
    isOpen: {
      type: Boolean,
      default: false,
    },
  },
  emits: {
    'close-modal': null,
  },
  setup(props, context) {
    const buttonClick = () => {
      context.emit('close-modal')
    }
    return {
      buttonClick
    }
  }
})
</script>

<style>
.modal {
  width: 200px;
  height: 200px;
  border: 2px solid #000;
  background: #fff;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
</style>